package top.dopen.home.work.common;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * <p>
 * 自定义的异常，捕捉指定异常类型，目前为全局拦截
 * </p>
 * TODO 日志记录
 * 自上到下匹配
 */
@ControllerAdvice
public class GlobalExceptionController {

	/**
	 * 默认异常拦截，全局性(理论不会调用)
	 * @param exception
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public ResponseEntity<Object> exception(Exception exception) {
		return new ResponseEntity<>("服务器发生异常 " + exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
	}
}